/**
 * 登录模块，提供登录相关业务功能
 * 
 * @Date: 2016-1-21
 * @author: Jackson wang
 * @version: 1.0
 * @since: 1.0
 */
define(["jquery", "datagridServ","sysmanMain", "bizProto","btnServ","msgServ","flowInit","buttonEvent"],
		function($,datagridServ, sysmanMain, bizProto,btnServ,msgServ,flowInit,buttonEvent) {

		'use strict';

		var _typeUrl = '/dictionary/getTree.action',_rootpath,
			item_code_dic_id = 36,
			rootId = 'panel-satisfaction-rank',
			edit_window_id='satisfaction-rank-win',
			el_width = 300,el_big_width=674,window_width=900,window_height=600
		
		var public_method ={
			
			/**
			 * 初始化新增页面
			 * @param _options.record 列表选中行
			 * @param _options.form 页面form对象
			 */
			initElement:function(_options){
				
			},
			/**
			 * @param _options.record
			 */
			buttonExtends:function(){
				return {'查看详情':private_method.detailInfo}
			},
			closeWindow:function(){
				$('#'+edit_window_id).empty()
				var _moduleConfig = sysmanMain.getCurrentModuConfig();
				_moduleConfig.initParam = {editable:true};
				sysmanMain.setCurrentModuConfig(_moduleConfig);
			},
			/**
			 * @param _options.rootId
			 * @param _options.conditionSelector
			 * @param _options.
			 */
			initList:function(_options){
				private_method.initCondition(_options)
			},
			reCreateField:function(_options){
				private_method.reCreateField(_options)
			},
			rowDblClick:function(index,row){
				private_method.rowDblClick(index,row)
			}
			
		}
		var private_method = {
			//查看详情
			detailInfo:function(){
				if(window.console){
					console.info('show detail loaded...')
				}
				
				var evaluateId = $('#'+edit_window_id + ' #evaluate_id')
				
				if(evaluateId.length>0){
					var evaluateIdValue = $(evaluateId).val();
					var detail_url = '/'+'honest'+'/satisEvaluateHis/query'+'/getSatisRankDetail.action?evaluate_id=' + evaluateIdValue
					var _param = {
						window:$('#satisfaction-rank-detail'),
						width:900,
						height:700,
						flag:false,
						existCheckElement:'#panel-satisfaction-rank'
					}
					datagridServ.windowEdit(_param);	
					var activityList = $('#satisfaction-rank-detail' +' table.dg-list');
				    var activityListGrid =	activityList.datagrid({
					url : detail_url,
					height : 600,
					columns:[[	       
						{field:'problem_subject',title:'问题内容',halign:'center',width:150}, 
						{field:'score',title:'问题分数(1,2为不满意)',width:60,align:'right',halign:'center',editor:'text'}
					]],
					rowStyler:function(index,row){   
				        if (row.score){
			        	 	if (row.score < 3){
			        			return 'background-color:pink;';				        			
				        	}		        			 
				        }   
				    },
				    rownumbers:true,
					animate: true,										
					striped:true,
					singleSelect:true,
					border:true,					
					idField: 'id',										
					fitColumns: true
				});
				
				    
				}
				
			},
			rowDblClick:function(index,row){
				
				var _param = {
					index:index,
					row:row,
					rootId:rootId,
					editWindow:edit_window_id,
					url:'/satisRank/editPage.action',
					moduleConfig:sysmanMain.getCurrentModuConfig(),
					onClose:public_method.closeWindow
				}				
				buttonEvent.doubleClickEdit(_param);
				
			},
			/**
			 * 初始化条件查询框
			 * @param _options.rootId 窗口根节点id
			 * @param _options.conditionSelector 条件框节点选择器
			 */
			initCondition:function(_options){
				if(window.console){
					console.info('satisRank init loaded and starting...')
				}
				
				flowInit.initList(_options)
			},
			reCreateField:function(_options){
				if(window.console){
					console.info(' satisRank reCreateField loaded and startting ...')
				}
				var normal_width_param = {width:el_width}
				var big_width_param = $.extend({},{width:el_big_width,multiline:true,height:50})
				var $form = _options.form
				
				_rootpath = '/'+sysmanMain.getRootPath()
				var selectedRecord = $('#' +rootId +' table.dg-list').datagrid('getSelected')
				
				
				var fConfig = {
					bizno:$.extend({fieldType:'textbox'},normal_width_param),	
					
					inquiry_date:$.extend({fieldType:'datebox'},normal_width_param),
					inquiry_reason:$.extend({fieldType:'textbox'},big_width_param),
					litigant_content:$.extend({fieldType:'textbox'},big_width_param),
					decide_content:$.extend({fieldType:'textbox'},big_width_param),
					affirm_content:$.extend({fieldType:'textbox'},big_width_param),
					litigant_name:$.extend(
						{
							fieldType:'textbox',
							onClickButton:function(data){
								var $dept_window = $('#win-dept-user');
									
								$($dept_window).attr('callback-id',edit_window_id+' #litigant_id')							
								$($dept_window).attr('callback-value',edit_window_id+' #litigant_name')
								
								$($dept_window).attr('callback-deptid',edit_window_id+' #litigant_deptid')							
								$($dept_window).attr('callback-deptValue',edit_window_id+' #litigant_deptname')
								
								sysmanMain.deptUserSelect()
							}
						}
						,
						normal_width_param
					),
					inquiry_item:$.extend(
						{fieldType:'combobox'},
						{
							textField:'name',
							valueField:'name',
							url:_rootpath + _typeUrl+'?id=' + item_code_dic_id,
							onSelect:function(record){
								var _item = $(_options.form).find('#inquiry_item_code')
								$(_item).val(record.id)
								
							}
						},
						normal_width_param),
					affirm_result:$.extend(
							{fieldType:'combobox'},
							{
								textField:'name',
								valueField:'name',
								url:_rootpath + _typeUrl+'?id=' + 112,
								onSelect:function(record){
									var _item = $(_options.form).find('#affirm_result_code')
									$(_item).val(record.id)
									
									var $username = $(_options.form).find('#affirm_name')
									var $userid = $(_options.form).find('#affirm_id')
									
									var curUser = sysmanMain.getCurrentUser()
									$($username).textbox('setValue',curUser.name)
									$($userid).val(curUser.id)
								}
							},
							normal_width_param)
				}
				
				flowInit.initField({
					fieldConfig:fConfig,
					fieldStatus:_options.data,
					window_id:edit_window_id
				})
			}
		}
			
			return public_method;

		});